import React, { Component } from 'react';
import { Divider, Table, Popconfirm } from 'antd';
import { isEmpty, isObject, map } from 'lodash';
import { createList } from '/common/components/HocCRUD';
import * as config from './config';
import MainWrap from '/common/components/HocCRUD/MainWrap';
import { actionFunc } from '@/pages/Host';

@createList({
  config,
  initSearchData: (props, data) => {
    return {
      ...data,
      fuzzyMatch: 'code,name',
    };
  },
  initFilterData: null,
})
export default class Department extends Component {
  /**
   * 子表格
   * @returns {*}
   */
  expandedRowRender(record, index, indent, expanded) {
    // console.log(record, index, indent, expanded);
    const columns = [
      { title: '序号', dataIndex: 'no', key: 'no' },
      { title: '岗位编码', dataIndex: 'code', key: 'code' },
      { title: '岗位名称', dataIndex: 'name', key: 'name' },
    ];

    const data = !isEmpty(record.positions) ?
      map(record.positions, (v, key) => ({ key, no: key + 1, ...v }))
      : [];
    return (
      <Table
        columns={columns}
        dataSource={data}
        pagination={false}
      />
    );
  };

  render() {

    const tableProps = {
      columns: [
        {
          title: '序号',
          dataIndex: 'no',
          key: 'no',
        },
        {
          title: '部门编码',
          dataIndex: 'code',
          key: 'code',
        },
        {
          title: '部门名称',
          dataIndex: 'name',
          key: 'name',

        },
       /* {
          title: '责任中心',
          dataIndex: 'rccc',
          key: 'rccc',
          render: (text) => {
            return isObject(text) ? text.name : '';
          },
        },*/

       /* {
          title: '所属站点',
          dataIndex: 'site',
          key: 'site',
          render: (text) => {
            // console.log(text);
            return isObject(text) ? text.name : '';
          },
        },*/
        {
          title: '操作',
          key: 'action',
          render: (text, record) => (actionFunc(this.props, text, record))


        },
      ],
      // expandedRowRender: this.expandedRowRender.bind(this),
    };

    return (

      <MainWrap
        {...this.props}
        tableProps={tableProps}
        headActionOption = {{export:false,import:false}}
      >
        {
          this.props.children
        }
      </MainWrap>
    );
  }
}
